<?php
//header("Content-Type: text/html; charset=utf8");
//echo $_POST['selectOp'];
//exit;//ok
include_once '../../php/dbconfig.php';
include_once "../dataaccess/common.php";
include_once '../dataaccess/city.php';
include_once '../dataaccess/venue.php';
include_once '../dataaccess/event_type.php';
include_once '../dataaccess/cs_parameter.php';
//echo show_country_region_data();
//exit;//ok
//if (isset($_POST['btConfirm']) && $_POST['btConfirm'] == '确定') {
//if (isset($_POST['btConfirm'])) {
//echo $_POST['selectOp']."<br>";
//

$cs_parameter=new cs_parameter();
$defaultPageSize= $cs_parameter->getPageSize();
$defaultPageNo=1;
if($defaultPageSize<=0)
    $defaultPageSize=10;
// 要用Jquery来替换显示区域

if (isset($_POST['selectOp']) && $_POST['selectOp'] == '1') {
    // City
    $where=$_POST['where'];
    echo buildCityScript();
    echo show_city_data($defaultPageSize,$defaultPageNo,$where);
    exit;
}
if (isset($_POST['selectOp']) && $_POST['selectOp'] == '2') {
    // Venue
    $where=$_POST['where'];
    echo buildVenueScript();
    echo show_venue_data($defaultPageSize,$defaultPageNo,$where);
    exit;
}
if (isset($_POST['selectOp']) && $_POST['selectOp'] == '3') {
    // Event Type
    $where=$_POST['where'];
    echo buildEventTypeScript();
    echo show_event_type_data($defaultPageSize,$defaultPageNo,$where);
    exit;
}
if (isset($_POST['selectOp']) && $_POST['selectOp'] == '4') {
    // configuration
    echo buildConfigScript();
    echo show_config_data();
    exit;
}
//弹出对话框
if (isset($_POST['opShowSelections'])) {
     $obj = json_decode($_POST['opShowSelections']);
     $showData="";
     switch($obj->_type)
     {
         case "CID":
            $showData= showCountryRegionSelection($obj->pageSize,$obj->pageNo,$obj->whereText);
             break;
         case "VID":
             $showData= showCitySelection($obj->pageSize,$obj->pageNo,$obj->whereText);
             break;
         default:
             break;
     }
     
     $showData=str_replace(array("\r\n", "\n", "\r","\n\r"),"",$showData);
     echo html_entity_decode(htmlentities($showData));
     exit;
}


//表单操作
if (isset($_POST['opHiddenMsg'])) {
    //echo "OK";
    // echo "<br>HiddenMsg: ".$_POST['opHiddenMsg']."<br>";
    $obj = json_decode($_POST['opHiddenMsg']);
    //print_r($obj); //debug
    //echo "<br>"; //debug
    //echo "<br>_op=> ".$obj->_op;
    //echo "<br>crid=> ".$obj->crid;
    switch ($obj->_op) {
        case "SHOW":
            switch ($obj->_type) {
                case "VID":
                    echo show_venue_data($obj->pageSize,$obj->pageNo,$obj->where);
                    exit;
                    break;
                case "ETID":
                    echo show_event_type_data($obj->pageSize,$obj->pageNo,$obj->where);
                    exit;
                    break;
                case "CID":
                    echo show_city_data($obj->pageSize,$obj->pageNo,$obj->where);
                    exit;
                    break;
                default:
                    break;
            }
            break;
        case "DELETE":
            switch ($obj->_type) {
                case "VID":
                    deleteVenue($obj->vid);
                    echo show_venue_data($defaultPageSize,$defaultPageNo);
                    exit;
                    break;
                case "ETID":
                    deleteEventType($obj->etid);
                    echo show_event_type_data($defaultPageSize,$defaultPageNo);
                    exit;
                    break;
                case "CID":
                    deleteCity($obj->cid);
                    echo show_city_data($defaultPageSize,$defaultPageNo);
                    exit;
                    break;
                default:
                    break;
            }
            break;
        case "INSERT":
            switch ($obj->_type) {
                case "VID":
                    $result=checkExistKey("venue",$obj->zh_hk);
                    if($result)
                    {
                        echo "EXISTKEY";
                    }
                    else
                    {
                        insertVenue($obj->zh_hk, $obj->cid, $obj->en_us, $obj->zh_cn, $obj->telephones, $obj->address_en_us, $obj->address_zh_hk, $obj->address_zh_cn,$obj->urls,$obj->contact_person);
                        echo show_venue_data($defaultPageSize,$defaultPageNo);
                    }
                    exit;
                    break;
                case "ETID":
                    $result=checkExistKey("event_type",$obj->zh_hk);
                    if($result)
                    {
                        echo "EXISTKEY";
                    }
                    else
                    {
                        insertEventType($obj->zh_hk, $obj->en_us, $obj->zh_cn,$obj->color_mark);
                        echo show_event_type_data($defaultPageSize,$defaultPageNo);
                    }
                    exit;
                    break;
                case "CID":
                    $result=checkExistKey("city",$obj->zh_hk);
                    if($result)
                    {
                        echo "EXISTKEY";
                    }
                    else
                    {
                        insertCity($obj->zh_hk, $obj->en_us, $obj->zh_cn);
                        echo show_city_data($defaultPageSize,$defaultPageNo);
                    }
                    exit;
                    break;
                default:
                    break;
            }
            break;
        case "UPDATE":
            switch ($obj->_type) {
                case "VID":
                    //$keyValue,$cid,$en_us="",$zh_cn="",$telephones="",$address_en_us="",$address_zh_hk="",$address_zh_cn=""
                    $result=checkExistKey("venue",$obj->zh_hk,"vid",$obj->vid);
                    if($result)
                    {
                        echo "EXISTKEY";
                    }
                    else
                    {
                        updateVenue($obj->vid, $obj->cid, $obj->zh_hk, $obj->en_us, $obj->zh_cn, $obj->telephones, $obj->address_en_us, $obj->address_zh_hk, $obj->address_zh_cn,$obj->urls,$obj->contact_person);
                        echo show_venue_data($defaultPageSize,$defaultPageNo);
                    }
                    exit;
                    break;
                case "ETID":
                    $result=checkExistKey("event_type",$obj->zh_hk,"etid",$obj->etid);
                    if($result)
                    {
                        echo "EXISTKEY";
                    }
                    else
                    {
                        updateEventType($obj->etid, $obj->zh_hk, $obj->en_us, $obj->zh_cn,$obj->color_mark);
                        echo show_event_type_data($defaultPageSize,$defaultPageNo);
                    }
                    exit;
                    break;
                case "CID":
                    $result=checkExistKey("city",$obj->zh_hk,"cid",$obj->cid);
                    if($result)
                    {
                        echo "EXISTKEY";
                    }
                    else
                    {
                        updateCity($obj->cid, $obj->zh_hk, $obj->en_us, $obj->zh_cn);
                        echo show_city_data($defaultPageSize,$defaultPageNo);
                    }
                    exit;
                    break;
                case "CFG":
                    updateConfiguration($obj->code,$obj->val);
                    echo show_config_data();
                    exit;
                    break;
                default:
                    break;
            }
            break;
        default:
            break;
    }
}

//========================================================UI====================
//--------------common control start--------------------------------------------
function buildHidden() {
    //用于测试
    return "<input type='hidden' id='hiddenMsg'></input>
        <input type='hidden' id='hiddenSelectItemID'></input>
        <input type='hidden' id='hiddenSelectItemText'></input>";
}

function buildNew() {
    return "<input type='image' value='new' id='btNew' onclick=\"btNewOnclick();\" src=\"../../css/images/icons/add.png\"/>[新增/保存]新記錄";
}
function checkExistKey($tableName,$value,$keyColumn="",$keyValue="",$keyColumnName="name_zh_hk")
{
    $baseinfo_common=new baseinfo_common();
    $result=$baseinfo_common->checkExistKeyValue($tableName, trim($value),$keyColumn,$keyValue,$keyColumnName);
    if($result==true||$result=="Sql error")
        return true;
    else
        return false;
}


//------------common control end------------------------------------------------
//------------------city start--------------------------------------------------
function show_city_data($pageSize=10,$pageNo=1,$where="") {
    $city_r = new city();
    //$handle = $city_r->select(10, 1); //测试时使用的分頁标准
    //$pageSize=10;//City的頁,配置值或默认值
    //$pageNo=1;//City的頁
    $pSize=$pageSize;//关联的Country Region显示的頁,为了测试时使用,平时应该是也City一样
    $pNo=$pageNo;//同上
    $handle = $city_r->selectDetail($pageSize, $pageNo,$where); //测试时使用的分頁标准
    $strDivHead="<div id='divCityShow'>";
    $strDivFooter="</div>";
    $strTableheader = "<table id='wcTableCR' border=0 cellspacing=1 cellpadding=0><tr><th>序號</th><th>英文名</th><th>繁體</th><th>簡體</th><th>删除</th><th>修改</th></tr>";
    $strTableFooter = "</table>";
    while (($row = mysql_fetch_object($handle)) != null) {
        $cid = $row->cid;
        $name_en_us = $row->name_en_us;
        $name_zh_hk = $row->name_zh_hk;
        $name_zh_cn = $row->name_zh_cn;
     
        if ($cid == null)
            $cid = "&nbsp;";
        if ($name_en_us == null)
            $name_en_us = "&nbsp;";
        if ($name_zh_hk == null)
            $name_zh_hk = "&nbsp;";
        if ($name_zh_cn == null)
            $name_zh_cn = "&nbsp;";
//<input type='text' value='" . $crid . "' id='t_crid_".$cid."' readonly/>
        $strTmpTr = "<tr id='" . $cid . "'><th>" . $cid . "</th>
            <th><input type='text' value='" . $name_en_us . "' id='t_en_" . $cid . "' readonly/></th>
            <th><input type='text' value='" . $name_zh_hk . "' id='t_hk_" . $cid . "' readonly/></th>
            <th><input type='text' value='" . $name_zh_cn . "' id='t_cn_" . $cid . "' readonly/></th>
            <th><input type='image' value='delete' id=\"del_" . $cid . "\" onclick=\"btDeleteOnclick(" . $cid . ");\" src=\"../../css/images/icons/delete.png\"/></th>
            <th><input type='image' value='edit' id=\"edit_" . $cid . "\" onclick=\"btUpdateOnclick(" . $cid . ");\" src=\"../../css/images/icons/edit.png\"/></th>
                </tr>";
        $strTableheader.=$strTmpTr;
    }
    $strTableheader.=$strTableFooter;

    //$script = buildCityScript();
    $hidden_t = buildHidden();
    $newbutton = buildNew();
    $cityPageInfo=showCityPageInfo($pageSize,$pageNo,$where);//$cityPageInfo
    return  $strDivHead.$strTableheader . $newbutton .$cityPageInfo. $hidden_t.$strTableFooter;//$script
}

function buildCityScript() {
    //<script src="../../src/json2.js" type="text/javascript"></script>也可以放到这里
    return '
        <script type="text/javascript">  
         var old_en;
         var old_hk;
         var old_cn;
         var n_cid;
            function btDeleteOnclick(id)
            {
                if(confirm("您確認[刪除]當前記錄?"))
                {
                    var op_city={
                    "_op":"DELETE",
                    "_type":"CID",
                    "cid":id
                    };
       
                    $("#hiddenMsg").val(JSON.stringify(op_city));
                   //$("#t_en_"+id).parent().parent().remove();
                    commint("DELETE",0);//提交
                }
            }
             function btUpdateOnclick(id)
            {
                if($("#t_en_"+id).attr("readonly")==true)
                {
                    old_en =$("#t_en_"+id).attr("value");
                    old_hk =$("#t_hk_"+id).attr("value");
                    old_cn =$("#t_cn_"+id).attr("value");
                 
                    $("#t_en_"+id).removeAttr("readonly");
                    $("#t_hk_"+id).removeAttr("readonly");
                    $("#t_cn_"+id).removeAttr("readonly");

                    var old_var={
                    "_en":old_en,
                    "_hk":old_hk,
                    "_cn":old_cn
                    };
                    $("#hidden_old_context").val(JSON.stringify(old_var));
                    

                    $("#edit_"+id).val("save");
                    $("#edit_"+id).attr("src","../../css/images/icons/Item.Save.gif");
                }
                else
                {   
                     _hk =$("#t_hk_"+id).attr("value");
                     if(_hk.replace("/^\s*(.*?)\s*$/","$1")=="")
                     {
                        alert("[繁體]名稱為關鍵字,不能為空,請修改後提交!");
                        return;
                     }
                    if(confirm("您確認[保存]當前記錄修改?"))
                    {
                         //post
                        var _en =$("#t_en_"+id).attr("value");
                        var _hk =$("#t_hk_"+id).attr("value");
                        var _cn =$("#t_cn_"+id).attr("value");
   
                        var op_city={
                                "_op":"UPDATE",
                                "_type":"CID",
                                "cid":id,
                                "en_us":_en,
                                "zh_hk":_hk,
                                "zh_cn":_cn
                                };

                                $("#hiddenMsg").val(JSON.stringify(op_city));
                                commint("EDIT",id);//提交
                    }
                    else
                    {
                            var json_old_var=JSON.parse($("#hidden_old_context").val());
                             $("#t_en_"+id).val(json_old_var._en);
                             $("#t_hk_"+id).val(json_old_var._hk);
                             $("#t_cn_"+id).val(json_old_var._cn);

                         
                        $("#t_en_"+id).attr("readonly",true);
                        $("#t_hk_"+id).attr("readonly",true);
                        $("#t_cn_"+id).attr("readonly",true);

                        $("#edit_"+id).val("edit");
                        $("#edit_"+id).attr("src","../../css/images/icons/edit.png");

                    }
                }
                
            }
            function btNewOnclick()
            {
               if($("#btNew").val()=="new")
                {
                        n_cid=$("table tr:last-child th:first-child").text();
                        n_cid=parseInt(n_cid)+1;
                         var strTR="<tr id=\'"+n_cid+"\'><th>"+n_cid + "</th>"+
                        "<th><input type=\'text\' value=\'\' id=\'t_en_"+n_cid+"\'/></th>"+
                        "<th><input type=\'text\' value=\'\' id=\'t_hk_"+n_cid+"\'/></th>"+
                        "<th><input type=\'text\' value=\'\' id=\'t_cn_"+n_cid+"\'/></th>"+
                        "<th>&nbsp;</th>"+
                        "<th>&nbsp;</th>"+
                        "</tr>"; 
                        $("#wcTableCR").append(strTR);
                        $("#btNew").val("save");
                        $("#btNew").attr("src","../../css/images/icons/Item.Save.gif");
                  }
                  else
                  {
                         _hk =$("#t_hk_"+n_cid).attr("value");
                         if(_hk.replace("/^\s*(.*?)\s*$/","$1")=="")
                         {
                            alert("[繁體]名稱為關鍵字,不能為空,請修改後提交!");
                            return;
                         }
                        if(confirm("您確認[保存]當前新記錄?"))
                        {
                                 //post&get
                                //alert("post to php");
                                old_en =$("#t_en_"+n_cid).attr("value");
                                old_hk =$("#t_hk_"+n_cid).attr("value");
                                old_cn =$("#t_cn_"+n_cid).attr("value");
                                var op_city={
                                "_op":"INSERT",
                                "_type":"CID",
                                "en_us":old_en,
                                "zh_hk":old_hk,
                                "zh_cn":old_cn
                                };
                                
                                $("#hiddenMsg").val(JSON.stringify(op_city));
                                commint("ADD",0);//提交
                        }
                        else
                        {
                                $("table tr:last-child").remove();
                                $("#btNew").val("new");
                                $("#btNew").attr("src","../../css/images/icons/add.png");
                        }
                        
                   }

            }
           
             //取City的分頁信息
             function selectCityPage(pageSize,pageNo,where)
             {
                 var op_city={
                    "_op":"SHOW",
                    "_type":"CID",
                    "pageSize":pageSize,
                    "pageNo":pageNo,
                    "where":where
                    };
                 $.post(
                    "jCfg.php",
                    {opHiddenMsg:JSON.stringify(op_city)},
                    function(data)
                    {
                       var $divCr=$("#divCityShow").parent();
                         $("#divCityShow").remove();
                         $divCr.html(data);
                     })
               }
	     
             function selectValue(id,text)
             {
                //alert("click me");
                $("#hiddenSelectItemID").val(id);
                $("#hiddenSelectItemText").val(text);
                
             }
             function commint(op,id)
            {
               //alert( $("#hiddenMsg").val());
               var result="0";
                $.post(
                    "jCfg.php",
                    {opHiddenMsg:$("#hiddenMsg").val()},
                    function(data){
                        if(data=="EXISTKEY")
                        {
                            alert("已經存在此名稱的關鍵字項,請修改繁體名稱後提交!");
                            var json_old_var=JSON.parse($("#hidden_old_context").val());
                             $("#t_en_"+id).val(json_old_var._en);
                             $("#t_hk_"+id).val(json_old_var._hk);
                             $("#t_cn_"+id).val(json_old_var._cn);
                        }
                        else
                        {
                            $("#showdata").html(data);
                            if(op=="ADD")
                            {
                                $("#btNew").val("new");
                                $("#btNew").attr("src","../../css/images/icons/add.png");
                            }
                            if(op=="EDIT")
                            {
                                $("#t_en_"+id).attr("readonly",true);
                                $("#t_hk_"+id).attr("readonly",true);
                                $("#t_cn_"+id).attr("readonly",true);

                                $("#edit_"+id).val("edit");
                                $("#edit_"+id).attr("src","../../css/images/icons/edit.png");
                            }
                        }
         
                    }
                )
            }
            </script>';
}

function deleteCity($id) {
    $c = new city();
    $c->delete($id);
}

function insertCity($zh_hk, $en_us="", $zh_cn="") {
    $c = new city();
    $c->insert($zh_hk,  $en_us, $zh_cn);
}

function updateCity($id, $zh_hk,  $en_us="", $zh_cn="") {
    $c = new city();
    $c->update($id, $zh_hk,  $en_us, $zh_cn);
}

function showCityPageInfo($pageSize,$pageNo,$where="")
{
     $cr = new city();
     $totalPages=$cr->getPages($pageSize,$where);
     $prePageNo=$pageNo-1;
     $nextPageNo=$pageNo+1;
     if($prePageNo<1)
         $prePageNo=1;
     if($nextPageNo>$totalPages)
         $nextPageNo=$totalPages;
     $divPageInfos="<div id='city_page_info'>
         <a href='' id='firstPage' onclick='selectCityPage(".$pageSize.",1,\"".$where."\");return false;'>第一頁</a>
         <a href='' id='prePage' onclick='selectCityPage(".$pageSize.",".$prePageNo.",\"".$where."\");return false;'>上一頁</a>
         <label id='pageInfos'>".$pageNo."/".$totalPages."</label>
         <a href='' id='nextPage' onclick='selectCityPage(".$pageSize.",".$nextPageNo.",\"".$where."\");return false;'>下一頁</a>
         <a href='' id='lastPage' onclick='selectCityPage(".$pageSize.",".$totalPages.",\"".$where."\");return false;'>第末頁</a>
         </div>";
     return $divPageInfos;
}

function showCitySelectionsPageInfo($pageSize,$pageNo,$where="")
{
     $cr = new city();
     $totalPages=$cr->getPages($pageSize,$where);
     $prePageNo=$pageNo-1;
     $nextPageNo=$pageNo+1;
     if($prePageNo<1)
         $prePageNo=1;
     if($nextPageNo>$totalPages)
         $nextPageNo=$totalPages;
     $divPageInfos="<div id='city_page_info'>
         <a href='' id='firstPage' onclick='selectCRPage(".$pageSize.",1);return false;'>第一頁</a>
         <a href='' id='prePage' onclick='selectCRPage(".$pageSize.",".$prePageNo.");return false;'>上一頁</a>
         <label id='pageInfos'>".$pageNo."/".$totalPages."</label>
         <a href='' id='nextPage' onclick='selectCRPage(".$pageSize.",".$nextPageNo.");return false;'>下一頁</a>
         <a href='' id='lastPage' onclick='selectCRPage(".$pageSize.",".$totalPages.");return false;'>第末頁</a>
         </div>";
     return $divPageInfos;
}
//------------------city end----------------------------------------------------
//------------------event type start--------------------------------------------
function show_event_type_data($pageSize=10,$pageNo=1,$where="") {
    $et_r = new event_type();
    $handle = $et_r->select($pageSize, $pageNo,$where); //测试时使用的分頁标准
    $strDivHead="<div id='divEventTypeShow'>";
    $strDivFooter="</div>";
    $strTableheader = "<table id='wcTableCR' border=0 cellspacing=1 cellpadding=0><tr><th>序號</th><th>英文名</th><th>繁體</th><th>簡體</th><th>顏色</th><th>删除</th><th>修改</th></tr>";
    $strTableFooter = "</table>";
    while (($row = mysql_fetch_object($handle)) != null) {
        $etid = $row->etid;
        $name_en_us = $row->name_en_us;
        $name_zh_hk = $row->name_zh_hk;
        $name_zh_cn = $row->name_zh_cn;
        $color_mark=$row->color_mark;
        if ($etid == null)
            $etid = "&nbsp;";
        if ($name_en_us == null)
            $name_en_us = "&nbsp;";
        if ($name_zh_hk == null)
            $name_zh_hk = "&nbsp;";
        if ($name_zh_cn == null)
            $name_zh_cn = "&nbsp;";
        if ($color_mark == null)
            $color_mark = "&nbsp;";

        $strTmpTr = "<tr id='" . $etid . "'><th>" . $etid . "</th>
            <th><input type='text' value='" . $name_en_us . "' id='t_en_" . $etid . "' readonly/></th>
            <th><input type='text' value='" . $name_zh_hk . "' id='t_hk_" . $etid . "' readonly/></th>
            <th><input type='text' value='" . $name_zh_cn . "' id='t_cn_" . $etid . "' readonly/></th>
            <th><input type='text' value='" . $color_mark . "' id='t_cl_" . $etid . "' readonly/></th>
            <th><input type='image' value='delete' id=\"del_" . $etid . "\" onclick=\"btDeleteOnclick(" . $etid . ");\" src=\"../../css/images/icons/delete.png\"/></th>
            <th><input type='image' value='edit' id=\"edit_" . $etid . "\" onclick=\"btUpdateOnclick(" . $etid . ");\" src=\"../../css/images/icons/edit.png\"/></th>
            </tr>";
        $strTableheader.=$strTmpTr;
    }
    $strTableheader.=$strTableFooter;

    //$script = buildEventTypeScript();
    $hidden_t = buildHidden();
    $newbutton = buildNew();//$script .
    $event_page_info=showEventTypePageInfo($pageSize,$pageNo,$where);
    return  $strDivHead.$strTableheader . $newbutton.$event_page_info . $hidden_t.$strDivFooter;
}

function buildEventTypeScript() {
    //<script src="../../src/json2.js" type="text/javascript"></script>也可以放到这里
    return '
        <script type="text/javascript">  
         var old_en;
         var old_hk;
         var old_cn;
         var n_id;
         function btDeleteOnclick(id)
            {
                if(confirm("您確認[刪除]當前記錄?"))
                {
                    var op_event_type={
                    "_op":"DELETE",
                    "_type":"ETID",
                    "etid":id
                    };
       
                    $("#hiddenMsg").val(JSON.stringify(op_event_type));
                    $("#t_en_"+id).parent().parent().remove();
                    commint("DELETE",0);//提交
                }
            }
             function btUpdateOnclick(id)
            {
                if($("#t_en_"+id).attr("readonly")==true)
                {
                    old_en =$("#t_en_"+id).attr("value");
                    old_hk =$("#t_hk_"+id).attr("value");
                    old_cn =$("#t_cn_"+id).attr("value");
                    old_cl =$("#t_cl_"+id).attr("value");
                  
                    $("#t_en_"+id).removeAttr("readonly");
                    $("#t_hk_"+id).removeAttr("readonly");
                    $("#t_cn_"+id).removeAttr("readonly");
                    $("#t_cl_"+id).removeAttr("readonly");
                     
                    var old_var={
                    "_en":old_en,
                    "_hk":old_hk,
                    "_cn":old_cn,
                    "_cl":old_cl
                    };
                    $("#hidden_old_context").val(JSON.stringify(old_var));
                    
                    $("#edit_"+id).val("save");
                    $("#edit_"+id).attr("src","../../css/images/icons/Item.Save.gif");
                }
                else
                {   
                     _hk =$("#t_hk_"+id).attr("value");
                     if(_hk.replace("/^\s*(.*?)\s*$/","$1")=="")
                     {
                        alert("[繁體]名稱為關鍵字,不能為空,請修改後提交!");
                        return;
                     }
                    if(confirm("您確認[保存]當前記錄修改?"))
                    {
                         //post
                        old_en =$("#t_en_"+id).attr("value");
                        old_hk =$("#t_hk_"+id).attr("value");
                        old_cn =$("#t_cn_"+id).attr("value");
                        old_cl =$("#t_cl_"+id).attr("value");
                        
                        var op_event_type={
                                "_op":"UPDATE",
                                "_type":"ETID",
                                "etid":id,
                                "en_us":old_en,
                                "zh_hk":old_hk,
                                "zh_cn":old_cn,
                                "color_mark":old_cl
                                };

                                $("#hiddenMsg").val(JSON.stringify(op_event_type));
                                commint("EDIT",id);//提交
                    }
                    else
                    {
                        var json_old_var=JSON.parse($("#hidden_old_context").val());
                             $("#t_en_"+id).val(json_old_var._en);
                             $("#t_hk_"+id).val(json_old_var._hk);
                             $("#t_cn_"+id).val(json_old_var._cn);
                             $("#t_cl_"+id).val(json_old_var._cl);
                         
                        $("#t_en_"+id).attr("readonly",true);
                        $("#t_hk_"+id).attr("readonly",true);
                        $("#t_cn_"+id).attr("readonly",true);
                        $("#t_cl_"+id).attr("readonly",true);
                        $("#edit_"+id).val("edit");
                        $("#edit_"+id).attr("src","../../css/images/icons/edit.png");
                         
                    }
                    
                  
                }
                
            }
            function btNewOnclick()
            {
               if($("#btNew").val()=="new")
                {

                        n_id=$("table tr:last-child th:first-child").text();
                        n_id=parseInt(n_id)+1;
                         var strTR="<tr id=\'"+n_id+"\'><th>"+n_id + "</th>"+
                        "<th><input type=\'text\' value=\'\' id=\'t_en_"+n_id+"\'/></th>"+
                        "<th><input type=\'text\' value=\'\' id=\'t_hk_"+n_id+"\'/></th>"+
                        "<th><input type=\'text\' value=\'\' id=\'t_cn_"+n_id+"\'/></th>"+
                        "<th><input type=\'text\' value=\'\' id=\'t_cl_"+n_id+"\'/></th>"+
                        "<th>&nbsp;</th>"+
                        "<th>&nbsp;</th>"+
                        "</tr>"; 
                      
                        $("#wcTableCR").append(strTR);
                        $("#btNew").val("save");
                        $("#btNew").attr("src","../../css/images/icons/Item.Save.gif");
                  }
                  else
                  {
                         _hk =$("#t_hk_"+n_id).attr("value");
                         if(_hk.replace("/^\s*(.*?)\s*$/","$1")=="")
                         {
                            alert("[繁體]名稱為關鍵字,不能為空,請修改後提交!");
                            return;
                         }
                        if(confirm("您確認[保存]當前新記錄?"))
                        {
                                 //post&get
                                //alert("post to php");
                                old_en =$("#t_en_"+n_id).attr("value");
                                old_hk =$("#t_hk_"+n_id).attr("value");
                                old_cn =$("#t_cn_"+n_id).attr("value");
                                old_cl =$("#t_cl_"+n_id).attr("value");
                                
                                var op_event_type={
                                "_op":"INSERT",
                                "_type":"ETID",
                                "en_us":old_en,
                                "zh_hk":old_hk,
                                "zh_cn":old_cn,
                                "color_mark":old_cl
                                };

                                $("#hiddenMsg").val(JSON.stringify(op_event_type));
                                commint("ADD",0);//提交
                              
                        }
                        else
                        {
                                $("table tr:last").remove();
                                $("#btNew").val("new");
                                $("#btNew").attr("src","../../css/images/icons/add.png");
                        }
                       
                   }

            }
             //取Event Type的分頁信息
             function selectEventTypePage(pageSize,pageNo,where)
             {
                 var op_event_type={
                    "_op":"SHOW",
                    "_type":"ETID",
                    "pageSize":pageSize,
                    "pageNo":pageNo,
                    "where":where
                    };
                 $.post(
                    "jCfg.php",
                    {opHiddenMsg:JSON.stringify(op_event_type)},
                    function(data)
                    {
                         var $divCr=$("#divEventTypeShow").parent();
                         $("#divEventTypeShow").remove();
                         $divCr.html(data);
                     })
               }
             function commint(op,id)
            {
               //alert( $("#hiddenMsg").val());
               var result="0";
                $.post(
                    "jCfg.php",
                    {opHiddenMsg:$("#hiddenMsg").val()},
                    function(data){
                        if(data=="EXISTKEY")
                        {
                            alert("已經存在此名稱的關鍵字項,請修改繁體名稱後提交!");
                             var json_old_var=JSON.parse($("#hidden_old_context").val());
                             $("#t_en_"+id).val(json_old_var._en);
                             $("#t_hk_"+id).val(json_old_var._hk);
                             $("#t_cn_"+id).val(json_old_var._cn);
                             $("#t_cl_"+id).val(json_old_var._cl);
                        }
                        else
                        {
                            $("#showdata").html(data);
                            if(op=="ADD")
                            {
                                $("#btNew").val("new");
                                $("#btNew").attr("src","../../css/images/icons/add.png");
                            }
                            if(op=="EDIT")
                            {
                                $("#t_en_"+id).attr("readonly",true);
                                $("#t_hk_"+id).attr("readonly",true);
                                $("#t_cn_"+id).attr("readonly",true);
                                $("#t_cl_"+id).attr("readonly",true);

                                $("#edit_"+id).val("edit");
                                $("#edit_"+id).attr("src","../../css/images/icons/edit.png");
                            }
                        }
         
                    }
                )
            }
            </script>';
}

function deleteEventType($id) {
    $c = new event_type();
    $c->delete($id);
}

function insertEventType($zh_hk, $en_us="", $zh_cn="",$color_mark="") {
    $c = new event_type();
    $c->insert($zh_hk, $en_us, $zh_cn,$color_mark);
}

function updateEventType($id, $zh_hk, $en_us="", $zh_cn="",$color_mark="") {
    $c = new event_type();
    $c->update($id, $zh_hk, $en_us, $zh_cn,$color_mark);
}
function showEventTypePageInfo($pageSize,$pageNo,$where="")
{
     $et = new event_type();
     $totalPages=$et->getTotalPages($pageSize,$where);
     $prePageNo=$pageNo-1;
     $nextPageNo=$pageNo+1;
     if($prePageNo<1)
         $prePageNo=1;
     if($nextPageNo>$totalPages)
         $nextPageNo=$totalPages;
     $divPageInfos="<div id='event_type_page_info'>
         <a href='' id='firstPage' onclick='selectEventTypePage(".$pageSize.",1,\"".$where."\");return false;'>第一頁</a>
         <a href='' id='prePage' onclick='selectEventTypePage(".$pageSize.",".$prePageNo.",\"".$where."\");return false;'>上一頁</a>
         <label id='pageInfos'>".$pageNo."/".$totalPages."</label>
         <a href='' id='nextPage' onclick='selectEventTypePage(".$pageSize.",".$nextPageNo.",\"".$where."\");return false;'>下一頁</a>
         <a href='' id='lastPage' onclick='selectEventTypePage(".$pageSize.",".$totalPages.",\"".$where."\");return false;'>第末頁</a>
         </div>";
     return $divPageInfos;
}
//------------------event type end----------------------------------------------
//------------------venue start--------------------------------------------
function show_venue_data($pageSize=10,$pageNo=1,$where="") {
    $pSize=$pageSize;
    $pNo=$pageNo;
    $v_r = new venue();
    $handle = $v_r->selectDetail($pageSize, $pageNo,$where); //测试时使用的分頁标准
    $strDivHead="<div id='divVenueShow'>";
    $strDivFooter="</div>";
    $strTableheader = "<table id='wcTableCR' border=0 cellspacing=1 cellpadding=0><tr><th>序號</th><th>英文名</th><th>繁體</th><th>簡體</th>
        <th>電話</th><th>地址(en)</th><th>地址(hk)</th><th>地址(cn)</th><th>網址</th><th>聯繫人</th><th>城市</th>
        <th>刪除</th><th>修改</th></tr>";
    $strTableFooter = "</table>";
    while (($row = mysql_fetch_object($handle)) != null) {
        $vid = $row->vid;
        $name_en_us = $row->name_en_us;
        $name_zh_hk = $row->name_zh_hk;
        $name_zh_cn = $row->name_zh_cn;
        $telephones = $row->telephones;
        $add_en_us = $row->address_en_us;
        $add_zh_hk = $row->address_zh_hk;
        $add_zh_cn = $row->address_zh_cn;
        $cid = $row->cid;
        $c_zh_hk=$row->c_zh_hk;
        $urls=$row->urls;
        $contact_person=$row->contact_person;
        if ($vid == null)
            $vid = "&nbsp;";
        if ($name_en_us == null)
            $name_en_us = "&nbsp;";
        if ($name_zh_hk == null)
            $name_zh_hk = "&nbsp;";
        if ($name_zh_cn == null)
            $name_zh_cn = "&nbsp;";
        if ($telephones == null)
            $telephones = "&nbsp;";
        if ($add_en_us == null)
            $add_en_us = "&nbsp;";
        if ($add_zh_hk == null)
            $add_zh_hk = "&nbsp;";
        if ($add_zh_cn == null)
            $add_zh_cn = "&nbsp;";
        if ($cid == null)
            $cid = "&nbsp;";
        if ($urls==null)
            $urls="&nbsp;";
        if ($contact_person==null)
            $contact_person="&nbsp;";


        $strTmpTr = "<tr id='" . $vid . "'><th>" . $vid . "</th>
            <th><input type='text' value='" . $name_en_us . "' id='t_en_" . $vid . "' readonly/></th>
            <th><input type='text' value='" . $name_zh_hk . "' id='t_hk_" . $vid . "' readonly/></th>
            <th><input type='text' value='" . $name_zh_cn . "' id='t_cn_" . $vid . "' readonly/></th>
                
            <th><input type='text' value='" . $telephones . "' id='t_tel_" . $vid . "' readonly/></th>
            <th><input type='text' value='" . $add_en_us . "' id='t_ad_en_" . $vid . "' readonly/></th>
            <th><input type='text' value='" . $add_zh_hk . "' id='t_ad_hk_" . $vid . "' readonly/></th>
            <th><input type='text' value='" . $add_zh_cn . "' id='t_ad_cn_" . $vid . "' readonly/></th>
            <th><input type='text' value='" . $urls . "' id='t_urls_" . $vid . "' readonly/></th>
            <th><input type='text' value='" . $contact_person . "' id='t_contact_person_" . $vid . "' readonly/></th>
                
            <th><a href='' id='t_cid_" . $vid . "' title='" . $cid . "' onclick=\"selectCR('" . $vid . "',".$pSize.",1);return false;\">" . $c_zh_hk . "</a></th>

            <th><input type='image' value='delete' id=\"del_" . $vid . "\" onclick=\"btDeleteOnclick(" . $vid . ");\" src=\"../../css/images/icons/delete.png\"/></th>
            <th><input type='image' value='edit' id=\"edit_" . $vid . "\" onclick=\"btUpdateOnclick(" . $vid . ");\" src=\"../../css/images/icons/edit.png\"/></th>
            </tr>";
        $strTableheader.=$strTmpTr;
    }
    $strTableheader.=$strTableFooter;

    //$script = buildVenueScript();
    $hidden_t = buildHidden();
    $newbutton = buildNew();//$script .
    $venue_page_info=showVenuePageInfo($pageSize,$pageNo,$where);
    return  $strDivHead.$strTableheader . $newbutton .$venue_page_info. $hidden_t.$strDivFooter;
}

function buildVenueScript() {
    //<script src="../../src/json2.js" type="text/javascript"></script>也可以放到这里
    return '
        <script type="text/javascript">  
         var old_en;
         var old_hk;
         var old_cn;
         var old_telephones;
         var old_add_en_us;
         var old_add_zh_hk;
         var old_add_zh_cn;
         var old_cid;
         var old_cid_text;
         var old_urls;
         var old_contact_person;
         var n_id;
            function btDeleteOnclick(id)
            {
                if(confirm("您確認[刪除]當前記錄?"))
                {
                    var op_venue={
                    "_op":"DELETE",
                    "_type":"VID",
                    "vid":id
                    };
       
                    $("#hiddenMsg").val(JSON.stringify(op_venue));
                    $("#t_en_"+id).parent().parent().remove();
                    commint("DELETE",0);//提交
                }
            }
             function btUpdateOnclick(id)
            {
                if($("#t_en_"+id).attr("readonly")==true)
                {
                    old_en =$("#t_en_"+id).attr("value");
                    old_hk =$("#t_hk_"+id).attr("value");
                    old_cn =$("#t_cn_"+id).attr("value");
                    old_telephones =$("#t_tel_"+id).attr("value");
                    old_add_en_us =$("#t_ad_en_"+id).attr("value");
                    old_add_zh_hk =$("#t_ad_hk_"+id).attr("value");
                    old_add_zh_cn =$("#t_ad_cn_"+id).attr("value");
                    
                    old_cid =$("#t_cid_"+id).attr("title");
                    old_cid_text=$("#t_cid_"+id).text();
                    
                    old_urls=$("#t_urls_"+id).attr("value");
                    old_contact_person=$("#t_contact_person_"+id).attr("value");
                 
                    $("#t_en_"+id).removeAttr("readonly");
                    $("#t_hk_"+id).removeAttr("readonly");
                    $("#t_cn_"+id).removeAttr("readonly");
                    
                    $("#t_tel_"+id).removeAttr("readonly");
                    $("#t_ad_en_"+id).removeAttr("readonly");
                    $("#t_ad_hk_"+id).removeAttr("readonly");
                    $("#t_ad_cn_"+id).removeAttr("readonly");
                    $("#t_cid_"+id).removeAttr("readonly");
                    $("#t_urls_"+id).removeAttr("readonly");
                    $("#t_contact_person_"+id).removeAttr("readonly");
                    
                    var old_var={
                    "_en":old_en,
                    "_hk":old_hk,
                    "_cn":old_cn,
                    "_telephones":old_telephones,
                    "_add_en":old_add_en_us,
                    "_add_hk":old_add_zh_hk,
                    "_add_cn":old_add_zh_cn,
                    "_cid":old_cid,
                    "_cid_text":old_cid_text,
                    "_urls":old_urls,
                    "_contact_person":old_contact_person
                    };
                    $("#hidden_old_context").val(JSON.stringify(old_var));
                    
                    $("#edit_"+id).val("save");
                    $("#edit_"+id).attr("src","../../css/images/icons/Item.Save.gif"); 
                }
                else
                {   
                     _hk =$("#t_hk_"+id).attr("value");
                     if(_hk.replace("/^\s*(.*?)\s*$/","$1")=="")
                     {
                        alert("[繁體]名稱為關鍵字,不能為空,請修改後提交!");
                        return;
                     }
                    if(confirm("您確認[保存]當前記錄修改?"))
                    {
                         //post
                        old_en =$("#t_en_"+id).attr("value");
                        old_hk =$("#t_hk_"+id).attr("value");
                        old_cn =$("#t_cn_"+id).attr("value");
                        old_telephones =$("#t_tel_"+id).attr("value");
                        old_add_en_us =$("#t_ad_en_"+id).attr("value");
                        old_add_zh_hk =$("#t_ad_hk_"+id).attr("value");
                        old_add_zh_cn =$("#t_ad_cn_"+id).attr("value");
                        old_urls=$("#t_urls_"+id).attr("value");
                        old_contact_person=$("#t_contact_person_"+id).attr("value");
                       
                        old_cid =$("#t_cid_"+id).attr("title");
                        //old_cid_text=$("#t_cid_"+id).text();
 
                        var op_venue={
                                "_op":"UPDATE",
                                "_type":"VID",
                                "vid":id,
                                "en_us":old_en,
                                "zh_hk":old_hk,
                                "zh_cn":old_cn,
                                "telephones":old_telephones,
                                "address_en_us":old_add_en_us,
                                "address_zh_hk":old_add_zh_hk,
                                "address_zh_cn":old_add_zh_cn,
                                "cid":old_cid,
                                "urls":old_urls,
                                "contact_person":old_contact_person
                                };

                                $("#hiddenMsg").val(JSON.stringify(op_venue));
                                commint("EDIT",id);//提交
                    }
                    else
                    {
                         var json_old_var=JSON.parse($("#hidden_old_context").val());
                             $("#t_en_"+id).val(json_old_var._en);
                             $("#t_hk_"+id).val(json_old_var._hk);
                             $("#t_cn_"+id).val(json_old_var._cn);
                             $("#t_tel_"+id).val(json_old_var._telephones);
                             $("#t_ad_en_"+id).val(json_old_var._add_en);
                             $("#t_ad_hk_"+id).val(json_old_var._add_hk);
                             $("#t_ad_cn_"+id).val(json_old_var._add_cn);

                             $("#t_cid_"+id).attr("title",json_old_var._cid);
                             $("#t_cid_"+id).text(json_old_var._cid_text);

                             $("#t_urls_"+id).val(json_old_var._urls);
                             $("#t_contact_person_"+id).val(json_old_var._contact_person);
                         
                        $("#t_en_"+id).attr("readonly",true);
                        $("#t_hk_"+id).attr("readonly",true);
                        $("#t_cn_"+id).attr("readonly",true);
                        $("#t_tel_"+id).attr("readonly",true);
                        $("#t_ad_en_"+id).attr("readonly",true);
                        $("#t_ad_hk_"+id).attr("readonly",true);
                        $("#t_ad_cn_"+id).attr("readonly",true);
                        $("#t_cid_"+id).attr("readonly",true);
                        $("#t_urls_"+id).attr("readonly",true);
                        $("#t_contact_person_"+id).attr("readonly",true);

                        $("#edit_"+id).val("edit");
                        $("#edit_"+id).attr("src","../../css/images/icons/edit.png");
                    }
                    

                }
                
            }
            function btNewOnclick()
            {
               if($("#btNew").val()=="new")
                {

                        n_id=$("table tr:last-child th:first-child").text();
                        n_id=parseInt(n_id)+1;
                         var strTR="<tr id=\'"+n_id+"\'><th>"+n_id + "</th>"+
                        "<th><input type=\'text\' value=\'\' id=\'t_en_"+n_id+"\'/></th>"+
                        "<th><input type=\'text\' value=\'\' id=\'t_hk_"+n_id+"\'/></th>"+
                        "<th><input type=\'text\' value=\'\' id=\'t_cn_"+n_id+"\'/></th>"+
                        "<th><input type=\'text\' value=\'\' id=\'t_tel_"+n_id+"\'/></th>"+
                        "<th><input type=\'text\' value=\'\' id=\'t_ad_en_"+n_id+"\'/></th>"+
                        "<th><input type=\'text\' value=\'\' id=\'t_ad_hk_"+n_id+"\'/></th>"+
                        "<th><input type=\'text\' value=\'\' id=\'t_ad_cn_"+n_id+"\'/></th>"+
                        "<th><input type=\'text\' value=\'\' id=\'t_urls_"+n_id+"\'/></th>"+
                        "<th><input type=\'text\' value=\'\' id=\'t_contact_person_"+n_id+"\'/></th>"+
                        "<th><a href=\'\' id=\'t_cid_" +n_id+ "\' title=\'" +n_id+ "\' onclick=\"selectCR(\'"+n_id+ "\',0,0);return false;\">Select...</a></th>"+
                        "<th>&nbsp;</th>"+
                        "<th>&nbsp;</th>"+
                        "</tr>"; 
                        $("#wcTableCR").append(strTR);
                        $("#btNew").val("save");
                        $("#btNew").attr("src","../../css/images/icons/Item.Save.gif");
                  }
                  else
                  {
                        old_cid_text =$("#t_cid_"+n_id).text();
                        if(old_cid_text=="Select...")
                        {
                            alert("請先選擇一個[城市],然後再保存!");
                            return;
                        }
                         _hk =$("#t_hk_"+n_id).attr("value");
                         if(_hk.replace("/^\s*(.*?)\s*$/","$1")=="")
                         {
                            alert("[繁體]名稱為關鍵字,不能為空,請修改後提交!");
                            return;
                         }
                        if(confirm("您確認[保存]當前新記錄?"))
                        {
                                 //post&get
                                //alert("post to php");
                                old_en =$("#t_en_"+n_id).attr("value");
                                old_hk =$("#t_hk_"+n_id).attr("value");
                                old_cn =$("#t_cn_"+n_id).attr("value");
                                old_telephones =$("#t_tel_"+n_id).attr("value");
                                old_add_en_us =$("#t_ad_en_"+n_id).attr("value");
                                old_add_zh_hk =$("#t_ad_hk_"+n_id).attr("value");
                                old_add_zh_cn =$("#t_ad_cn_"+n_id).attr("value");
                                old_urls =$("#t_urls_"+n_id).attr("value");
                                old_contact_person =$("#t_contact_person_"+n_id).attr("value");
                                old_cid =$("#t_cid_"+n_id).attr("title");
                               
                                
                                var op_venue={
                                "_op":"INSERT",
                                "_type":"VID",
                                "en_us":old_en,
                                "zh_hk":old_hk,
                                "zh_cn":old_cn,
                                "telephones":old_telephones,
                                "address_en_us":old_add_en_us,
                                "address_zh_hk":old_add_zh_hk,
                                "address_zh_cn":old_add_zh_cn,
                                "cid":old_cid,
                                "urls":old_urls,
                                "contact_person":old_contact_person
                                };

                                $("#hiddenMsg").val(JSON.stringify(op_venue));
                                commint("ADD",0);//提交
                              
                        }
                        else
                        {
                                $("table tr:last-child").remove();
                                $("#btNew").val("new");
                                $("#btNew").attr("src","../../css/images/icons/add.png");
                        }
                      
                   }

            }
               function selectCR(id,pageSize,pageNo)
             {
                //alert(id);
                //alert($("#edit_"+id).val());
                //$("#edit_"+id).val("edit");
                if($("#edit_"+id).val()=="edit")
                {
                    //alert($("#edit_"+id).val());
                    return;
                }
                   
               
                 var opSelections={
                    "_type":"VID",
                    "pageSize":pageSize,
                    "pageNo":pageNo,
                    "whereText":""
                    };
                 $.post(
                    "jCfg.php",
                    {opShowSelections:JSON.stringify(opSelections)},
                    function(data){
                         jAlert(data,"请选择[城市]",function(r)
                         {
                            if(r)
                            {
                                 
                                  var nid=$("#hiddenSelectItemID").val();
                                  var ntext=$("#hiddenSelectItemText").val();
                                   //alert(nid+ntext);
                                   if(nid!="" && ntext!="")
                                   {
                                     // newData="<label id=\'t_crid_"+nid+ "\' title=\'"+nid+ "\' onclick=\"selectCR(\'" +nid+ "\');\">" +ntext+ "</label>";
                                     $("#t_cid_"+id).attr("title",nid);
                                     $("#t_cid_"+id).text(ntext);
                                   }
                                  $("#hiddenSelectItemID").val("");
                                  $("#hiddenSelectItemText").val("");
                            }
                         });
                     })
                // }
             }
             //取CountryRegion的分頁信息
             function selectCRPage(pageSize,pageNo)
             {
                 var tmpWhereText=$("#inWhereCRtext").val();
                 var opSelections={
                    "_type":"VID",
                    "pageSize":pageSize,
                    "pageNo":pageNo,
                    "whereText":tmpWhereText
                    };
                 $.post(
                    "jCfg.php",
                    {opShowSelections:JSON.stringify(opSelections)},
                    function(data)
                    {
                         var $divCr=$("#divShowSelections").parent();
                         $("#divShowSelections").remove();
                         $divCr.html(data);
                         $("#inWhereCRtext").val(tmpWhereText);
                     })
             }
               function selectValue(id,text)
             {
                //alert("click me");
                $("#hiddenSelectItemID").val(id);
                $("#hiddenSelectItemText").val(text);
                
             }
         //Venue的分頁信息
             function selectVenuePage(pageSize,pageNo,where)
             {
                 var op_venue={
                    "_op":"SHOW",
                    "_type":"VID",
                    "pageSize":pageSize,
                    "pageNo":pageNo,
                    "where":where
                    };
                 $.post(
                    "jCfg.php",
                    {opHiddenMsg:JSON.stringify(op_venue)},
                    function(data)
                    {
                         var $divCr=$("#divVenueShow").parent();
                         $("#divVenueShow").remove();
                         $divCr.html(data);
                     })
               }
            function commint(op,id)
            {
               //alert( $("#hiddenMsg").val());
               var result="0";
                $.post(
                    "jCfg.php",
                    {opHiddenMsg:$("#hiddenMsg").val()},
                    function(data){
                        if(data=="EXISTKEY")
                        {
                            alert("已經存在此名稱的關鍵字項,請修改繁體名稱後提交!");
                            var json_old_var=JSON.parse($("#hidden_old_context").val());
                             $("#t_en_"+id).val(json_old_var._en);
                             $("#t_hk_"+id).val(json_old_var._hk);
                             $("#t_cn_"+id).val(json_old_var._cn);
                             $("#t_tel_"+id).val(json_old_var._telephones);
                             $("#t_ad_en_"+id).val(json_old_var._add_en);
                             $("#t_ad_hk_"+id).val(json_old_var._add_hk);
                             $("#t_ad_cn_"+id).val(json_old_var._add_cn);

                             $("#t_cid_"+id).attr("title",json_old_var._cid);
                             $("#t_cid_"+id).text(json_old_var._cid_text);

                             $("#t_urls_"+id).val(json_old_var._urls);
                             $("#t_contact_person_"+id).val(json_old_var._contact_person);
                        }
                        else
                        {
                            $("#showdata").html(data);
                            if(op=="ADD")
                            {
                                $("#btNew").val("new");
                                $("#btNew").attr("src","../../css/images/icons/add.png");
                            }
                            if(op=="EDIT")
                            {
                                $("#t_en_"+id).attr("readonly",true);
                                $("#t_hk_"+id).attr("readonly",true);
                                $("#t_cn_"+id).attr("readonly",true);
                                $("#t_tel_"+id).attr("readonly",true);
                                $("#t_ad_en_"+id).attr("readonly",true);
                                $("#t_ad_hk_"+id).attr("readonly",true);
                                $("#t_ad_cn_"+id).attr("readonly",true);
                                $("#t_cid_"+id).attr("readonly",true);
                                $("#t_urls_"+id).attr("readonly",true);
                                $("#t_contact_person_"+id).attr("readonly",true);

                                $("#edit_"+id).val("edit");
                                $("#edit_"+id).attr("src","../../css/images/icons/edit.png");
                            }
                        }
         
                    }
                )
            }
            </script>';
}

function deleteVenue($id) {
    $c = new venue();
    $c->delete($id);
}

function insertVenue($zh_hk, $cid, $en_us="", $zh_cn="", $telephones="", $address_en_us="", $address_zh_hk="", $address_zh_cn="",$urls="",$contact_person="") {
    $c = new venue();
    $c->insert($zh_hk, $cid, $en_us, $zh_cn, $telephones, $address_en_us, $address_zh_hk, $address_zh_cn,$urls,$contact_person);
}

function updateVenue($id, $cid, $zh_hk, $en_us="", $zh_cn="", $telephones="", $address_en_us="", $address_zh_hk="", $address_zh_cn="",$urls="",$contact_person="") {
    $c = new venue();
    $c->update($id, $cid, $zh_hk, $en_us, $zh_cn, $telephones, $address_en_us, $address_zh_hk, $address_zh_cn,$urls,$contact_person);
}
function showVenuePageInfo($pageSize,$pageNo,$where="")
{
     $v = new venue();
     $totalPages=$v->getTotalPages($pageSize,$where);
     $prePageNo=$pageNo-1;
     $nextPageNo=$pageNo+1;
     if($prePageNo<1)
         $prePageNo=1;
     if($nextPageNo>$totalPages)
         $nextPageNo=$totalPages;
     $divPageInfos="<div id='venue_page_info'>
         <a href='' id='firstPage' onclick='selectVenuePage(".$pageSize.",1,\"".$where."\");return false;'>第一頁</a>
         <a href='' id='prePage' onclick='selectVenuePage(".$pageSize.",".$prePageNo.",\"".$where."\");return false;'>上一頁</a>
         <label id='pageInfos'>".$pageNo."/".$totalPages."</label>
         <a href='' id='nextPage' onclick='selectVenuePage(".$pageSize.",".$nextPageNo.",\"".$where."\");return false;'>下一頁</a>
         <a href='' id='lastPage' onclick='selectVenuePage(".$pageSize.",".$totalPages.",\"".$where."\");return false;'>第末頁</a>
         </div>";
     return $divPageInfos;
}

function showCitySelection($pageSize, $pageNo,$whereText="") {
    $city_s = new city();
    $where="";
    if($whereText!="")
    {
    $where="name_zh_hk LIKE '%".$whereText."%'
            OR name_en_us LIKE '%".$whereText."%'
            OR name_zh_cn LIKE '%".$whereText."%'";
    }
    if($pageSize<=0)
        $pageSize=10;//default
    if($pageNo<=0)
        $pageNo=1;//default
    $handle = $city_s->select($pageSize, $pageNo,$where); //测试时使用的分頁标准
    $strDivheader="<div id='divShowSelections'>";
    $strDivfooter="</div>";
    $strTableheader = "<table id='showSelections' border=1 cellspacing=1 width=300><tr><th>序號</th><th>英文名</th><th>繁體</th><th>簡體</th></tr>";
    $strTableFooter = "</table>";
    while (($row = mysql_fetch_object($handle)) != null) {
        $crid = $row->cid;
        $name_en_us = $row->name_en_us;
        $name_zh_hk = $row->name_zh_hk;
        $name_zh_cn = $row->name_zh_cn;
        if ($crid == null)
            $crid = "&nbsp;";
        if ($name_en_us == null)
            $name_en_us = "&nbsp;";
        if ($name_zh_hk == null)
            $name_zh_hk = "&nbsp;";
        if ($name_zh_cn == null)
            $name_zh_cn = "&nbsp;";

        $strTmpTr = "<tr id='" . $crid . "'>
            <th><input type=\"radio\" name =\"cr\" value=\"" . $crid . "\" id=\"ck_" . $crid . "\" onclick=\"selectValue(" . $crid . ",'" . $name_zh_hk . "');\"/>" . $crid . "</th>
            <th><label for=\"ck_" . $crid . "\" onclick=\"selectValue(" . $crid . ",'" . $name_zh_hk . "');\">" . $name_en_us . "</label></th>
            <th><label for=\"ck_" . $crid . "\" onclick=\"selectValue(" . $crid . ",'" . $name_zh_hk . "');\">" . $name_zh_hk . "</label></th>
            <th><label for=\"ck_" . $crid . "\" onclick=\"selectValue(" . $crid . ",'" . $name_zh_hk . "');\">" . $name_zh_cn . "</label></th>
            </tr>";
        $strTableheader.=$strTmpTr;
    }
    //$strTableheader.=$strTableFooter;
    $strSeacher="<div id='divWhereCRText'><input type='text' value='' id='inWhereCRtext'/><input type='button' value='查找' id='btWhereCRText' onclick='selectCRPage(".$pageSize.",1);'/></div>";
    $pageStr=showCitySelectionsPageInfo($pageSize,$pageNo,$where);
    $show=$strDivheader.$strSeacher.$strTableheader.$strTableFooter.$pageStr.$strDivfooter;
    return $show;
}

//------------------venue end----------------------------------------------
//------------------config start----------------------------------------------
function show_config_data() {
    $cs_p = new cs_parameter();
    $handle = $cs_p->select(); //测试时使用的分頁标准
    $strDivHead="<div id='divConfigurationShow'>";
    $strDivFooter="</div>";
    $strTableheader = "<table id='wcTableCR' border=0 cellspacing=1 cellpadding=0><tr><th>配置項</th><th>配置值</th><th>描述</th><th>修改</th></tr>";
    $strTableFooter = "</table>";
    while (($row = mysql_fetch_object($handle)) != null) {
        $code = $row->parameter_code;
        $parameter_value = $row->parameter_value;
        $description = $row->description;
        if ($code == null)
            $code = "&nbsp;";
        if ($parameter_value == null)
            $parameter_value = "&nbsp;";
        if ($description == null)
            $description = "&nbsp;";

        $strTmpTr = "<tr id='" . $code . "'>
            <td><input type='text' value='" . $code . "' id='t_code_".$code."' readonly/></label></td>
            <td><input type='text' value='" . $parameter_value . "' id='t_val_" . $code . "' readonly/></td>
            <td><input type='text' value='" . $description . "' id='t_des_" . $code . "' readonly/></label></td>
            <td><input type='image' value='edit' id=\"edit_" . $code . "\" onclick=\"btUpdateOnclick('" . $code . "');\" src=\"../../css/images/icons/edit.png\"/></td>
                </tr>";
        $strTableheader.=$strTmpTr;
    }
    $strTableheader.=$strTableFooter;

    $hidden_t = buildHidden();

    return  $strDivHead.$strTableheader . $hidden_t.$strDivFooter;
}
function updateConfiguration($code, $value) {
    $c = new cs_parameter();
    $c->update($code,$value);
}
function buildConfigScript() {
    //<script src="../../src/json2.js" type="text/javascript"></script>也可以放到这里
    return '
        <script type="text/javascript">  
         var old_code;
         var old_val;
         //var old_des;
           function btUpdateOnclick(id)
            {
                if($("#t_val_"+id).attr("readonly")==true)
                {
                    old_code =$("#t_code_"+id).attr("value");
                    old_val =$("#t_val_"+id).attr("value");
                    //old_des =$("#t_des_"+id).attr("value");

                    $("#t_val_"+id).removeAttr("readonly");
                    
                    $("#edit_"+id).val("save");
                    $("#edit_"+id).attr("src","../../css/images/icons/Item.Save.gif");
                }
                else
                {   
                    if(confirm("您確認[保存]當前記錄修改?"))
                    {
                         //post
                       old_code =$("#t_code_"+id).attr("value");
                       old_val =$("#t_val_"+id).attr("value");
                       //old_des =$("#t_des_"+id).attr("value");
                        
                        var op_config={
                                "_op":"UPDATE",
                                "_type":"CFG",
                                "code":old_code,
                                "val":old_val
                                };

                                $("#hiddenMsg").val(JSON.stringify(op_config));
                                commint();//提交
                    }
                    else
                    {
                         //$("#t_code_"+id).val(old_code);
                         $("#t_val_"+id).val(old_val);
                        // $("#t_des_"+id).val(old_des);
                         
                    }
                    
                    $("#t_val_"+id).attr("readonly",true);
                  
                    
                    $("#edit_"+id).val("edit");
                    $("#edit_"+id).attr("src","../../css/images/icons/edit.png");
                }
                
            }
        
             function commint()
            {
               //alert( $("#hiddenMsg").val());
                $.post(
                    "jCfg.php",
                    {opHiddenMsg:$("#hiddenMsg").val()},
                    function(data){
                        $("#showConfiguration").html(data);
         
                    }
                )
            }
            </script>';
}
//------------------config end----------------------------------------------
?>
